package com.uzhie.jt808.msg.entity;

import com.uzhie.jt808.JT808MsgBody;
import com.uzhie.jt808.msg.entity.BitConverter;
import com.uzhie.jt808.msg.entity.MyBuffer;

/**
 * 立即拍照指令
 * Created by lilongfei on 2018/8/9.
 */
public class JT_8801 implements JT808MsgBody {

    //通道号
    byte channel;
    //拍摄指令,张数,0表示停止,0xffff表示摄像
    int takeOrder;
    //间隔时间
    int span;
    //保存标识 1 保存,0 实时上传
    byte flag;
    //分辨率
    /**
     * 01 320*240
     * 02 640*480
     * 03 800*600
     * 04 1024*768
     * 05 174*144
     * 06 352*288
     * 07 704*288
     * 08 704*576
     */
    byte resolution;
    //图片质量  1~10 ,1最清楚
    byte quality;
    //亮度
    byte light;
    //对比度
    byte contrast;
    //饱和度
    byte saturation;
    //色度
    byte chroma;

    /**
     *
     * @param channel 通道号
     * @param takeOrder 拍照张数
     * @param resolution 分辨率
     */
    public JT_8801(int channel,int takeOrder,int resolution){
        this(channel,takeOrder,0,resolution);
    }

    public JT_8801(int channel,int takeOrder,int flag,int resolution){
        this(channel,takeOrder,0,flag,resolution,0,0,0,0,0);
    }

    public JT_8801(int channel, int takeOrder, int span, int flag, int resolution, int quality, int light, int contrast, int saturation, int chroma) {
        this.channel = BitConverter.GetBytes(channel)[3];
        this.takeOrder = takeOrder;
        this.span = span;
        this.flag = BitConverter.GetBytes(flag)[3];
        this.resolution = BitConverter.GetBytes(resolution)[3];
        this.quality = BitConverter.GetBytes(quality)[3];
        this.light = BitConverter.GetBytes(light)[3];
        this.contrast = BitConverter.GetBytes(contrast)[3];
        this.saturation = BitConverter.GetBytes(saturation)[3];
        this.chroma = BitConverter.GetBytes(chroma)[3];

    }

    public byte getChannel() {
        return channel;
    }

    public void setChannel(byte channel) {
        this.channel = channel;
    }

    public int getTakeOrder() {
        return takeOrder;
    }

    public void setTakeOrder(int takeOrder) {
        this.takeOrder = takeOrder;
    }

    public int getSpan() {
        return span;
    }

    public void setSpan(int span) {
        this.span = span;
    }

    public byte getFlag() {
        return flag;
    }

    public void setFlag(byte flag) {
        this.flag = flag;
    }

    public byte getResolution() {
        return resolution;
    }

    public void setResolution(byte resolution) {
        this.resolution = resolution;
    }

    public byte getQuality() {
        return quality;
    }

    public void setQuality(byte quality) {
        this.quality = quality;
    }

    public byte getLight() {
        return light;
    }

    public void setLight(byte light) {
        this.light = light;
    }

    public byte getContrast() {
        return contrast;
    }

    public void setContrast(byte contrast) {
        this.contrast = contrast;
    }

    public byte getSaturation() {
        return saturation;
    }

    public void setSaturation(byte saturation) {
        this.saturation = saturation;
    }

    public byte getChroma() {
        return chroma;
    }

    public void setChroma(byte chroma) {
        this.chroma = chroma;
    }

    @Override
    public byte[] WriteToBytes() {
        MyBuffer buffer = new MyBuffer();
        buffer.put(getChannel());
        buffer.put(BitConverter.GetBytes16(getTakeOrder()));
        buffer.put(BitConverter.GetBytes16(getSpan()));
        buffer.put(getFlag());
        buffer.put(getResolution());
        buffer.put(getQuality());
        buffer.put(getLight());
        buffer.put(getContrast());
        buffer.put(getSaturation());
        buffer.put(getChroma());
        return buffer.array();
    }

    @Override
    public void ReadFromBytes(byte[] body) {
        MyBuffer buffer = new MyBuffer(body);
        setChannel(buffer.get());
        setTakeOrder(BitConverter.ToUInt16(buffer.gets(2), 0));
        setSpan(BitConverter.ToUInt16(buffer.gets(2), 0));
        setFlag(buffer.get());
        setResolution(buffer.get());
        setQuality(buffer.get());
        setLight(buffer.get());
        setContrast(buffer.get());
        setSaturation(buffer.get());
        setChroma(buffer.get());
    }
}
